package com.code.androiddemo.cardslidepanel;

import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.code.androiddemo.R;
import com.code.androiddemo.base.BaseFragment;
import com.socks.library.KLog;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;

public class CardFragment extends BaseFragment {
    @Bind(R.id.card_left_btn)
    Button cardLeftBtn;
    @Bind(R.id.card_right_btn)
    Button cardRightBtn;
    @Bind(R.id.card_bottom_layout)
    LinearLayout cardBottomLayout;
    @Bind(R.id.image_slide_panel)
    CardSlidePanel imageSlidePanel;

    private CardSlidePanel.CardSwitchListener cardSwitchListener;

    private String imagePaths[] = {"assets://wall01.jpg",
            "assets://wall02.jpg", "assets://wall03.jpg",
            "assets://wall04.jpg", "assets://wall05.jpg",
            "assets://wall06.jpg", "assets://wall07.jpg",
            "assets://wall08.jpg", "assets://wall09.jpg",
            "assets://wall10.jpg", "assets://wall11.jpg",
            "assets://wall12.jpg", "assets://wall01.jpg",
            "assets://wall02.jpg", "assets://wall03.jpg",
            "assets://wall04.jpg", "assets://wall05.jpg",
            "assets://wall06.jpg", "assets://wall07.jpg",
            "assets://wall08.jpg", "assets://wall09.jpg",
            "assets://wall10.jpg", "assets://wall11.jpg", "assets://wall12.jpg"}; // 24个图片资源名称

    private String names[] = {"郭富城", "刘德华", "张学友", "李连杰", "成龙", "谢霆锋", "李易峰",
            "霍建华", "胡歌", "曾志伟", "吴孟达", "梁朝伟", "周星驰", "赵本山", "郭德纲", "周润发", "邓超",
            "王祖蓝", "王宝强", "黄晓明", "张卫健", "徐峥", "李亚鹏", "郑伊健"}; // 24个人名

    private List<CardDataItem> dataList = new ArrayList<>();


    @Override
    protected int getContentViewLayoutId() {
        return R.layout.fragment_card;
    }

    @Override
    protected void initViewAndEvents() {
        cardSwitchListener = new CardSlidePanel.CardSwitchListener() {

            @Override
            public void onShow(int index) {
                KLog.d("CardFragment", "正在显示-" + dataList.get(index).getUserName());
            }

            @Override
            public void onCardVanish(int index, int type) {
                Log.d("CardFragment", "正在消失-" + dataList.get(index).getUserName() + " 消失type=" + type);
            }

            @Override
            public void onItemClick(View cardView, int index) {
                Log.d("CardFragment", "卡片点击-" + dataList.get(index).getUserName());
            }
        };
        imageSlidePanel.setCardSwitchListener(cardSwitchListener);

        prepareDataList();
        imageSlidePanel.fillData(dataList);
    }

    private void prepareDataList() {
        int num = imagePaths.length;

        for (int j = 0; j < 3; j++) {
            for (int i = 0; i < num; i++) {
                CardDataItem dataItem = new CardDataItem();
                dataItem.setUserName(names[i]);
                dataItem.setImagePath(imagePaths[i]);
                dataItem.setLikeNum((int) (Math.random() * 10));
                dataItem.setImageNum((int) (Math.random() * 6));
                dataList.add(dataItem);
            }
        }
    }
}
